package main

import (
	"flag"
	"gitee.com/yysf_xin/go-common/db"
	"gitee.com/yysf_xin/go-notifier"
	_ "gitee.com/yysf_xin/go-notifier/http"
	"net/http"
)

func createNotifier(cfg *db.Config) *notifier.Notifier {
	client, err := db.NewClient(cfg, nil)
	if err != nil {
		panic(err)
	}
	n, err := notifier.New(client)
	if err != nil {
		panic(err)
	}
	return n
}
func main() {
	cfg := &db.Config{
		DbName:   "notifier.db",
		LogLevel: 4,
		Upgrade:  false,
	}
	flag.StringVar(&cfg.DbName, "db", "notifier.db", "db name")
	flag.IntVar(&cfg.LogLevel, "level", 1, "log level")
	flag.BoolVar(&cfg.Upgrade, "u", false, "upgrade db")
	flag.Parse()

	n := createNotifier(cfg)
	err := http.ListenAndServe("localhost:8001", n)
	if err != nil {
		panic(err)
	}
}
